package com.automapper.sqlbuilder.impl;

import java.util.Map;

import com.automapper.constants.FetchMode;
import com.automapper.query.CriteriaImpl;
import com.automapper.sqlbuilder.SqlBuilderTemplate;
import com.automapper.utils.ParameterUtils;
import com.automapper.utils.PropertiesFacade;

public class SelectRouterSqlBuilder extends SqlBuilderTemplate {	
	
	@Override
	public String buildSql(Object parameterObject, PropertiesFacade propertiesFacade) throws Exception {  
		Map<String, Object> parameterMap = (Map<String, Object>) parameterObject;
		//获取传入参数
		CriteriaImpl criteria = (CriteriaImpl) ParameterUtils.getParameter(parameterMap);
		FetchMode fetchMode = criteria.getFetchMode();
		SqlBuilderTemplate sqlBuilder;
		switch (fetchMode) {
			case ASSOCIATION_PAGE_BY_PARENT:
				sqlBuilder = new SelectAssociationPageByParentSqlBuilder();
				break;
			default :
				sqlBuilder = new SelectSqlBuilder();
				sqlBuilder = new SelectAssociationPageByParentSqlBuilder();
				break;
		}
		return sqlBuilder.buildSql(parameterObject, propertiesFacade);
	}  
}
